package chap3_8;

import java.io.*;

/**
 * @author https://gitee.com/W_Jun
 * @date 2021-12-13 22:05
 * @Description 案例：复制java文件（字符缓冲流改进版）
 */
public class CopyJavaDemo01 {
    public static void main(String[] args) throws IOException {
        //根据数据源创建字符缓冲输入流对象
        BufferedReader br = new BufferedReader(new FileReader("chapter03-字符流\\src\\chap3_4\\ConversionStreamDemo.java"));
        //根据目的地创建字符缓冲输出流对象
        BufferedWriter bw = new BufferedWriter(new FileWriter("chapter03-字符流\\Copy.java"));

        //读写数据，复制文件
        //一次读写一个字符
/*
        int ch;
        while ((ch = br.read()) != -1) {
            bw.write((char) ch);
        }
        */
        //一次读写一个字符数组
        int len;
        char[] chs = new char[1024];
        while ((len = br.read(chs)) != -1) {
            bw.write(new String(chs, 0, len));
        }

        //释放资源
        bw.close();
        br.close();
    }
}
